# Create your views here.
from django.short_cuts import render_to_response,redirect
from musiclink.utils import get_genre_info_list


def home(request):
    return render_to_response()


###
# anno id part
###
def random_anno_id(request):
    ml = MidLink.all().filter('kid =',-1).\
            filter('bid =',-1)[0]
    return redirect('/musiclink/anno_id?k=%s'%(str(ml.key())))

def anno_id(request):
    """
    get from cache the data need to anno
    """
    k = request.GET['k']
    ml = MidLink.get(k)
    dic = {'m':ml}
    return render_to_reponse('/musiclink/anno_id.html',dic)

##
# anno genre part
##
def random_anno_genre(request):
    # try to get one without genre annotation
    ml = MidLink.all().filter('anno_genre =',0)[0]
    return redirect('/musiclink/anno_genre?k=%s'%(str(ml.key())))


def anno_genre(request):
    #get a music that have no genre annotation
    k = request.GET['k']
    ml = MidLink.get(k)

    # get all genre info from the memcache
    genre_info_list = get_genre_info_list()

    dic = {'m':ml,'genre_info_list':genre_info_list}
    return render_to_response('/musiclink/anno_genre.html',dic)

